package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author : xiongke
 * @Description:
 * @Date: 2024/8/30
 */
@Api(tags = "管理端订单相关接口")
@Slf4j
@RestController("adminOrderController")
@RequestMapping("/admin/order")
public class OrderController {

    @Resource
    OrdersService ordersService;

    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO dto) {
        log.info("订单搜索");
        PageResult result = ordersService.queryPage(dto);
        return Result.success(result);
    }

    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO result = ordersService.statistics();
        return Result.success(result);
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO dto) {
        log.info("取消订单：{}", dto);
        ordersService.cancelOrder(dto);
        return Result.success();
    }

    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id) {
        log.info("订单：{}已经完成", id);
        ordersService.complete(id);
        return Result.success();
    }


    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO dto) {
        log.info("接单：{}", dto);
        ordersService.confirmOrder(dto);
        return Result.success();
    }

    @ApiOperation("派送")
    @PutMapping("/delivery/{id}")
    public Result deliver(@PathVariable Long id) {
        log.info("开始派送：{}", id);
        ordersService.deliver(id);
        return Result.success();
    }

    @ApiOperation("查询订单详情")
    @GetMapping("details/{id}")
    public Result<OrderVO> queryDetails(@PathVariable Long id) {
        log.info("查询订单详情：{}", id);
        OrderVO orderVO = ordersService.orderDetail(id);
        return Result.success(orderVO);
    }

    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto) {
        log.info("订单：{}被拒绝接单", dto.getId());
        ordersService.rejection(dto);
        return Result.success();
    }
}
